clc;
close all;
clear all;

N = 8;
k = 2;
lower = 0.0;
upper = 0.9999999999;
step = 2^(-N);
qtl = 2^(-N - k);
C = 4 * qtl;
ulp = 2^(-N);
num = (floor((upper-lower)/step) + 1);
ulp_line = ones(num,num) * ulp;
err = zeros(num,num);

id = 0;
for a = lower:step:upper
    for b = lower:step:upper
        id = id + 1;
        ans_t = a * b;
        
        [ans_tc, sum_tc] = trunc_mult(a, b, C, N, N, N, k);
        err(id) = abs(ans_t - ans_tc);
    end
end
save('err_stat.mat');
%% PLOT
figure;
title('ERROR STAT');
plot(err(:), 'r-+');hold on;
plot(ulp_line(:), 'g--');

legend('ERR_TOT', 'ULP');